# 什么是深浅拷贝?
# 拷贝 -- copy   复制了一份

# l1 = [1,2,3,4,[5,6,7,]]
# l2 = l1  # 赋值    赋值不是拷贝
# l1.append(8)
# print(l1)
# print(l2)

# l1 = [1,2,3,4,[4,5,6]]
# l2 = l1[:]   # 浅拷贝
# l2 = l1.copy() # 浅拷贝  -- 只拷贝第一层
# print(id(l1[0]))
# print(id(l2[0]))
# # 浅拷贝会创建一个新的列表(容器),
# 新创建的列表中的元素和原列表的元素用的是同一个内存空间

# l1 = [1,2,3,4]
# l2 = l1.copy()
# print(l1)
# print(id(l1))
# print(id(l2))
# print(id(l1[0]))
# print(id(l2[0]))

li = [1,2,32,[3,4,5]]
l2 = li.copy()

# li.append(8)
# print(l2)
# print(li)

# li[-1].append(8)
# print(l2)

# l1 = [1,2,3,(1,2,3)]
# l2 = l1.copy()
# l2[-1] = 6
# print(l1)  # 不变
# print(l2)  # 不变

# l1 = [1,2,3,4,[5,6,7,]]
# l2 = l1.copy()
# l1[-1].append(8)
# print(l2)  #[1,2,3,4,[5,6,7,8]]

# li = [1,2,3,4,]
# l2 = li  # 赋值   两个变量指向了一个列表内存地址
# li.append(9)
# print(l2)

# l1 = [1,2,3,4,5,]
# l2 = l1.copy()
# l1.append(8)
# print(l2)
# print(l1)

# l1 = [1,2,3,[4,5,6]]
# l2 = l1.copy()
# l2[-1] = 77
# print(l1)
# print(l2)

# 深拷贝:
# import copy
# li = [1,2,3,4,5,[6,7,8]]
# l2 = copy.deepcopy(li)
# print(li)
# # print(id(li))
# print(id(li[-1]))
# print(l2)
# # print(id(l2))
# print(id(l2[-1]))

# 深拷贝 --
#   不可变的数据类型和原列表指向同一个空间
#   可变数据会创建一个新的空间

import copy
# li = [1,2,3,4,5,[6,7,8]]
# l2 = copy.deepcopy(li)
# li[-1].append(678)
# print(l2)


# import copy
# li = [3,4,5,[1,2,3,4],6,7,8,{"k":'v'}]
# l2 = copy.deepcopy(li)
# li[-1]['k'] = "a"
# print(li)
# print(l2)

# 深浅拷贝怎么用?

# dic = {}   # "v":4
# li = []    #[{"v":0},{"v":1},{"v":2},{"v":3},{"v":4}]
# for i in range(0,5):
#     dic["v"] = i
#     li.append(dic)
# print(li)

# 深浅拷贝在哪用?
# 1.面试
# 2.不让修改原数据的时候,使用